package cocurrency.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * Created by luzl on 4/6/2017.
 */
public class FutureTaskTest {
    public static void main(String[] args) throws Exception {
        //one thread to get result in block way
        CallableThread  test=new CallableThread();
        FutureTask<Integer> futureTask=new FutureTask<Integer>(test);
        new Thread(futureTask).start();
        System.out.println("Test ...");
        System.out.println("Result ..."+futureTask.get().intValue());
        System.out.println("futureTask.isDone=>"+futureTask.isDone());

        //one thread to get result in none block way
        test=new CallableThread();
        futureTask=new FutureTask<Integer>(test);
        while (!futureTask.isDone()){
            System.out.println("Waiting to complete!");
            Thread.currentThread().sleep(1000);
        }
        System.out.println("Result ..."+futureTask.get().intValue());

    }
}
